package com.example.demo.zaqizabatest;

import lombok.SneakyThrows;

import java.util.concurrent.CountDownLatch;

/**
 * @ClassName CountDownLacthaa
 * @Author lys4134
 * @Date 2021/09/08 17:39:35
 * @Description CountDownLacthaa
 * @Version 1.0
 **/
@SuppressWarnings("AlibabaAvoidManuallyCreateThread")
public class CountDownLatchDemo {
    private static void print(String s){
        System.out.println(s);
    }



    @SneakyThrows
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(3);
        // a,b,c输出顺序随机，但是end一定是需要在三个线程执行完才输出
        new Thread(() -> {
            print("a");
            countDownLatch.countDown();
        }).start();
        new Thread(() -> {
            print("b");
            countDownLatch.countDown();
        }).start();
        new Thread(() -> {
            print("c");
            countDownLatch.countDown();
        }).start();
        countDownLatch.await();
        System.out.println("end");
    }
}
